#!/usr/bin/env make
###################################################################################
#
#  Copyright (c) Hunan Goke,Chengdu Goke,Shandong Goke. 2021.
#  All rights reserved.
#  Create By Caizhiyong 2021/3/16
#
###################################################################################
GDB             := gdb-7.9.1

NCURSES         := ncurses-6.0

GDB_PREFIX      := $(ROOTFS_BUILDDIR)/$(GDB)/.install

NCURSES_PREFIX  := $(ROOTFS_BUILDDIR)/$(NCURSES)/.install


###################################################################################
rootfs_unstrip: $(ROOTFS_PREFIX)/bin/gdb

clean: $(GDB).clean $(UUIDLIB).clean $(ZLIB).clean

$(GDB).clean:
	rm -rf $(ROOTFS_BUILDDIR)/$(GDB)

$(ROOTFS_PREFIX)/bin/gdb: $(ROOTFS_BUILDDIR)/$(GDB)/.built
	$(call mkdir,$(@D))
	cp -arf $(GDB_PREFIX)/bin/gdb $(ROOTFS_PREFIX)/bin
	touch $@

$(ROOTFS_BUILDDIR)/$(GDB)/.built: $(ROOTFS_BUILDDIR)/$(GDB)/.extracted \
									   $(ROOTFS_BUILDDIR)/$(NCURSES)/.built
	cd $(<D); CC=$(CROSS_COMPILE)-gcc ./configure \
		--prefix=$(GDB_PREFIX) \
		--host=$(CROSS_COMPILE) \
		CFLAGS='-lm'\
		--disable-tui\
		LDFLAGS=-L$(NCURSES_PREFIX)/lib \
		gdb_cv_prfpregset_t_broken=no
	make -C $(<D)
	make -C $(<D) install
	touch $@

$(ROOTFS_BUILDDIR)/$(GDB)/.extracted:
	$(call mkdir,$(@D))
	tar xf $(OPEN_SOURCE_DIR)/gdb/$(GDB).tar.gz -C $(ROOTFS_BUILDDIR)
	touch $@

###################################################################################
$(NCURSES).clean:
	rm -rf $(ROOTFS_BUILDDIR)/$(NCURSES)

$(ROOTFS_BUILDDIR)/$(NCURSES)/.built: $(ROOTFS_BUILDDIR)/$(NCURSES)/.extracted
	cd $(<D); CC=$(CROSS_COMPILE)-gcc ./configure \
		--prefix=$(NCURSES_PREFIX) \
		CPPFLAGS="-P" \
		--host=$(CROSS_COMPILE)
	make -C $(<D)
	make -C $(<D) install
	touch $@

$(ROOTFS_BUILDDIR)/$(NCURSES)/.extracted:
	$(call mkdir,$(@D))
	tar xf $(OPEN_SOURCE_DIR)/ncurses/$(NCURSES).tar.bz2 -C $(ROOTFS_BUILDDIR)
	touch $@
